﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[assembly: log4net.Config.XmlConfigurator(Watch = true, ConfigFile = "log4net.config")]
namespace HuiZe.education.Common
{
    public class Logger
    {
        public static readonly log4net.ILog log = log4net.LogManager.GetLogger("root");

        public static void WriteLog(string str)
        {
            log.Info(str);
        }

        /// <summary>
        /// 异常日志的写入
        /// </summary>
        /// <param name="content">内容</param>
        /// <param name="level"></param>
        /// <returns>写入结果</returns>
        public static void ErrorLog(String content, object ex = null)
        {
            if (ex == null)
            {
                log.Error("Error:" + content);
            }
            else if (ex is Exception)
            {
                Exception e = ex as Exception;
                log.Error(string.Format("Error:{0}\r\nex.Message:{1}\r\nex.StackTrace:{2}", content, e.Message ?? "", e.StackTrace ?? ""));
            }
            else
            {
                log.Error("Error:" + content + ex.ToString());
            }
        }
    }
}
